package silo.dungeonbuddy;

import java.awt.Color;
import java.awt.Graphics;
//import java.awt.Rectangle;

public abstract class FlatImage extends SelectableItem
{
	protected int x;/** The current x location of this entity */
	protected int y;/** The current y location of this entity */
	protected String spriteRef;
	protected Sprite sprite;/** The sprite that represents this entity */
	protected int sizeX;
	protected int sizeY;
	protected boolean visible;
	protected Start game;
	protected boolean onBoard;

	public FlatImage(String eName, String ref, Start game, int eX,int eY, int eSizeX, int eSizeY)
	{
		super(eName);
		sprite = SpriteStore.get().getSprite(ref);
		x = eX;
		y = eY;
		this.game = game;
		visible = true;
		sizeX=eSizeX;
		sizeY=eSizeY;
		spriteRef=ref;
		onBoard=true;
	}
	
	public void death()
	{
		
	}

	public void draw(Graphics g)
	{
		if(onBoard)
		{
			sprite.draw(g,((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+game.getOffsetX().getValue(),((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+game.getOffsetY().getValue(),game,sizeX,sizeY,onBoard);
			if(this==game.getSelectedPiece())
			{
				g.setColor(Color.darkGray);
				g.drawRect(((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+1+game.getOffsetX().getValue(),((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+1+game.getOffsetY().getValue(),(int)Math.floor(sizeX*(game.getHeight()/game.getSquaresPerScreen()))-2,(int)Math.floor(sizeY*(game.getHeight()/game.getSquaresPerScreen()))-2);
				g.drawLine(((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue()+(int)((0.5*sizeX)*(game.getHeight()/game.getSquaresPerScreen())),((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue()+(int)((0.5*sizeY)*(game.getHeight()/game.getSquaresPerScreen()))-6,((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue()+(int)((0.5*sizeX)*(game.getHeight()/game.getSquaresPerScreen())),((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue()+(int)((0.5*sizeY)*(game.getHeight()/game.getSquaresPerScreen()))+5);
				g.drawLine(((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue()+(int)((0.5*sizeX)*(game.getHeight()/game.getSquaresPerScreen()))-6,((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue()+(int)((0.5*sizeY)*(game.getHeight()/game.getSquaresPerScreen())),((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue()+(int)((0.5*sizeX)*(game.getHeight()/game.getSquaresPerScreen()))+5,((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue()+(int)((0.5*sizeY)*(game.getHeight()/game.getSquaresPerScreen())));
				g.setColor(Color.white);
				g.drawRect(((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue(),((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue(),(int)Math.floor(sizeX*(game.getHeight()/game.getSquaresPerScreen()))-4,(int)Math.floor(sizeY*(game.getHeight()/game.getSquaresPerScreen()))-4);
				g.drawLine(((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue()+(int)((0.5*sizeX)*(game.getHeight()/game.getSquaresPerScreen()))-1,((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue()+(int)((0.5*sizeY)*(game.getHeight()/game.getSquaresPerScreen()))-6,((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue()+(int)((0.5*sizeX)*(game.getHeight()/game.getSquaresPerScreen()))-1,((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue()+(int)((0.5*sizeY)*(game.getHeight()/game.getSquaresPerScreen()))+5);
				g.drawLine(((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue()+(int)((0.5*sizeX)*(game.getHeight()/game.getSquaresPerScreen()))-6,((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue()+(int)((0.5*sizeY)*(game.getHeight()/game.getSquaresPerScreen()))-1,((x/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetX().getValue()+(int)((0.5*sizeX)*(game.getHeight()/game.getSquaresPerScreen()))+5,((y/(game.getHeight()/20))*(game.getHeight()/game.getSquaresPerScreen()))+2+game.getOffsetY().getValue()+(int)((0.5*sizeY)*(game.getHeight()/game.getSquaresPerScreen()))-1);
				
				//Draw Resizing square
				if(!game.getClient())
				{
					g.setColor(Color.darkGray);
					g.drawRect((((x/(game.getHeight()/20))+sizeX)*(game.getHeight()/game.getSquaresPerScreen()))+1+game.getOffsetX().getValue()-5,(((y/(game.getHeight()/20))+sizeY)*(game.getHeight()/game.getSquaresPerScreen()))+1+game.getOffsetY().getValue()-5,6,6);
					g.setColor(Color.white);
					g.fillRect((((x/(game.getHeight()/20))+sizeX)*(game.getHeight()/game.getSquaresPerScreen()))+1+game.getOffsetX().getValue()-4,(((y/(game.getHeight()/20))+sizeY)*(game.getHeight()/game.getSquaresPerScreen()))+1+game.getOffsetY().getValue()-4,4,4);
				}
			}
		}else
		{
			sprite.draw(g,x,y,game,sizeX,sizeY,onBoard);
		}
	}//draw(g)
	
	public void draw(Graphics g,int x,int y)
	{
		sprite.draw(g,x,y,game,sizeX,sizeY,onBoard);
	}//draw(g)
	
	public void draw(Graphics g, MapForm sender)
	{
		sprite.draw(g,((x/(sender.getHeight()/20))*(sender.getHeight()/sender.getSquaresPerScreen()))+sender.getOffsetX().getValue(),((y/(sender.getHeight()/20))*(sender.getHeight()/sender.getSquaresPerScreen()))+sender.getOffsetY().getValue(),sizeX,sizeY,sender);
	}//draw(g,sender)
	
	public void changeImage(String ref)
	{
		sprite = SpriteStore.get().getSprite(ref);
		spriteRef = ref;
	}
	
	//GETTERS
	public int getX()
	{
		return x;
	}
	public int getY()
	{
		return y;
	}
	public boolean getVisible()
	{
		return visible;
	}
	public int getSizeX()
	{
		return sizeX;
	}
	public int getSizeY()
	{
		return sizeY;
	}
	public String getRef()
	{
		return spriteRef;
	}
	
	//SETTERS
	public void setVisible(boolean eVisible)
	{
		visible = eVisible;
	}
	public void setOnBoard(boolean eOnBoard)
	{
		onBoard=eOnBoard;
	}
	public void setX(int eX)
	{
		x=eX;
	}
	public void setY(int eY)
	{
		y=eY;
	}
	public void setSizeX(int eSize)
	{
		sizeX=eSize;
	}
	public void setSizeY(int eSize)
	{
		sizeY=eSize;
	}
	
	//toString
	public String toString()
	{
		if(visible)
		{
			return "0" + "," + x + "," + y + "," + spriteRef + "," + sizeX + "," + sizeY + "," + "1" + ",";
		}else
		{
			return "0" + "," + x + "," + y + "," + spriteRef + "," + sizeX + "," + sizeY + "," + "0" + ",";
		}
	}//toString
}